import React, {Component} from 'react'
import {connect} from 'react-redux'
import UrlPattern from 'url-pattern'
import {Card, Icon} from 'antd'

import OnlineCodingAnswer from './assignment/online-coding-answer'
import * as actions from '../actions/online-coding-answer'

import {tutorAnswerPageUrl} from '../constant/constant-url'

class TutorAnswerPage extends Component {
  constructor () {
    super()
    this.state = {
      quizId: 0
    }
  }
  componentDidMount () {
    const pattern = new UrlPattern(tutorAnswerPageUrl)
    const urlParams = pattern.match(this.props.location.pathname)
    this.setState({
      quizId: urlParams.quizId
    })
    this.props.getOnlineCodingAnswer(urlParams.quizId)
  }

  render () {
    const onlineCodingQuiz = this.props.onlineCodingQuiz
    return (<div>
      <Card title={<a onClick={() => window.history.back()}><Icon type='arrow-left' />返回作业详情</a>} noHovering bordered={false}>
        <OnlineCodingAnswer onlineCodingQuiz={onlineCodingQuiz} />
      </Card>
    </div>)
  }
}

const mapStateToProps = (state) => {
  return {
    onlineCodingQuiz: state.onlineCodingAnswer
  }
}

const mapDispatchToProps = (dispatch) => {
  return {
    getOnlineCodingAnswer: (quizId) => {
      dispatch(actions.getOnlineCodingAnswer(quizId))
    }

  }
}

export default connect(mapStateToProps, mapDispatchToProps)(TutorAnswerPage)
